home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / c / nullmodem / src / cmd.c next >
C/C++ Source or Header  |  1995-12-18  |  6KB  |  242 lines

  1. #include "defs.h"
  2. #include "protos.h"
  3.  
  4. struct IOExtSer *
  5. cmd_invalid(struct IOExtSer *iob)
  6. {
  7. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  8.  
  9.     iob->IOSer.io_Error = IOERR_NOCMD;
  10.     dprintf(unit, 1,"*** cmd_invalid\n");
  11.     return(iob);
  12. }
  13.  
  14. struct IOExtSer *
  15. cmd_reset(struct IOExtSer *iob)
  16. {
  17. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  18.  
  19.     dprintf(unit, 1,"*** cmd_reset\n");
  20.     return(iob);
  21. }
  22.  
  23. struct IOExtSer *
  24. cmd_read(struct IOExtSer *iob)
  25. {
  26. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  27. unsigned int count;
  28. char *r, *w = iob->IOSer.io_Data;
  29.  
  30.     ObtainSemaphore(&unit->u_Modem->nm_Semaphore);
  31.  
  32.     r = unit->u_Readptr;
  33.  
  34.     if( unit->u_Bufcount < iob->IOSer.io_Length ) {
  35.         count = iob->IOSer.io_Actual = unit->u_Bufcount;
  36.         AddTail( (struct List *)&unit->u_Readlist, &iob->IOSer.io_Message.mn_Node );
  37.         iob->IOSer.io_Flags &= ~IOF_QUICK;
  38.         dprintf(unit, 1, "cmd_read %ld (queued)\n", iob->IOSer.io_Length);
  39.         iob = NULL;
  40.     }
  41.     else {
  42.         count = iob->IOSer.io_Actual = iob->IOSer.io_Length;
  43.         dprintf(unit, 1, "cmd_read %ld (complete)\n", iob->IOSer.io_Length);
  44.     }
  45.  
  46.     unit->u_Bufcount -= count;
  47.  
  48.     /*
  49.      *  copy chars from the buffer to the read request, quickly
  50.      */
  51.     while( count-- ) {
  52.         *w++ = *r--;
  53.         if( r < unit->u_Buffer ) r += UNIT_BUF_SIZE;
  54.     }
  55.  
  56.     unit->u_Readptr = r;
  57.  
  58.     /* and let the task know we took something */
  59.     Signal(unit->u_Modem->nm_Taskptr, SIGBREAKF_CTRL_C);
  60.  
  61.     ReleaseSemaphore(&unit->u_Modem->nm_Semaphore);
  62.  
  63.     return(iob);
  64. }
  65.  
  66. struct IOExtSer *
  67. cmd_write(struct IOExtSer *iob)
  68. {
  69. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  70.  
  71.     /*
  72.      *  handle the case of a null-terminated string write
  73.      */
  74.     if( iob->IOSer.io_Length == -1 ) {
  75.     char *p = iob->IOSer.io_Data;
  76.  
  77.         while( *p ) p++;
  78.         iob->IOSer.io_Length = p - iob->IOSer.io_Data;
  79.     }
  80.  
  81.     ObtainSemaphore(&unit->u_Modem->nm_Semaphore);
  82.  
  83.     dprintf(unit, 1, "cmd_write %ld (queued)\n" ,iob->IOSer.io_Length);
  84.  
  85.     /*
  86.      *  we let the Task handle where it goes, just queue it
  87.      *  and tell her we sent something
  88.      */
  89.     AddTail( (struct List *)&unit->u_Writelist, &iob->IOSer.io_Message.mn_Node );
  90.     iob->IOSer.io_Flags &= ~IOF_QUICK;
  91.     Signal(unit->u_Modem->nm_Taskptr, SIGBREAKF_CTRL_C);
  92.  
  93.     ReleaseSemaphore(&unit->u_Modem->nm_Semaphore);
  94.  
  95.     return(NULL);   /* its always queued */
  96. }
  97.  
  98. struct IOExtSer *
  99. cmd_update(struct IOExtSer *iob)
  100. {
  101. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  102.  
  103.     iob->IOSer.io_Error = IOERR_NOCMD;
  104.     dprintf(unit, 1, "cmd_update\n");
  105.     return(iob);
  106. }
  107.  
  108. struct IOExtSer *
  109. cmd_clear(struct IOExtSer *iob)
  110. {
  111. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  112.  
  113.     ObtainSemaphore(&unit->u_Modem->nm_Semaphore);
  114.  
  115.     dprintf(unit, 1, "cmd_clear (was %ld)\n",unit->u_Bufcount);
  116.  
  117.     unit->u_Bufcount = 0;
  118.     unit->u_Readptr = unit->u_Writeptr = unit->u_Buffer;
  119.  
  120.     ReleaseSemaphore(&unit->u_Modem->nm_Semaphore);
  121.  
  122.     return(iob);
  123. }
  124.  
  125. struct IOExtSer *
  126. cmd_stop(struct IOExtSer *iob)
  127. {
  128. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  129.  
  130.     dprintf(unit, 1, "cmd_stop (not implemented)\n");
  131.     return(iob);
  132. }
  133.  
  134. struct IOExtSer *
  135. cmd_start(struct IOExtSer *iob)
  136. {
  137. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  138.  
  139.     dprintf(unit, 1, "cmd_start (not implemented)\n");
  140.     return(iob);
  141. }
  142.  
  143. struct IOExtSer *
  144. cmd_flush(struct IOExtSer *iob)
  145. {
  146. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  147. struct IOExtSer *io,*temp;
  148.  
  149.     dprintf(unit, 1, "cmd_flush\n");
  150.  
  151.     ObtainSemaphore(&unit->u_Modem->nm_Semaphore);
  152.  
  153.     io = unit->u_Readlist.mlh_Head;
  154.     while( temp = io->IOSer.io_Message.mn_Node.ln_Succ ) {
  155.         dprintf(unit, 2, "cmd_flush flushed read (read %ld of %ld)\n",io->IOSer.io_Actual,io->IOSer.io_Length);
  156.         Remove(&io->IOSer.io_Message.mn_Node);
  157.         ReplyMsg(&io->IOSer.io_Message);
  158.         io = temp;
  159.     }
  160.  
  161.     io = unit->u_Writelist.mlh_Head;
  162.     while( temp = io->IOSer.io_Message.mn_Node.ln_Succ ) {
  163.         dprintf(unit, 2, "cmd_flush flushed write (written %ld of %ld)\n",io->IOSer.io_Actual,io->IOSer.io_Length);
  164.         Remove(&io->IOSer.io_Message.mn_Node);
  165.         ReplyMsg(&io->IOSer.io_Message);
  166.         io = temp;
  167.     }
  168.  
  169.     ReleaseSemaphore(&unit->u_Modem->nm_Semaphore);
  170.  
  171.     return(iob);
  172. }
  173.  
  174. struct IOExtSer *
  175. sdcmd_query(struct IOExtSer *iob)
  176. {
  177. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  178.  
  179.     ObtainSemaphore(&unit->u_Modem->nm_Semaphore);
  180.  
  181.     iob->IOSer.io_Actual = unit->u_Bufcount;
  182.     iob->io_Status = (unit->u_SReg[SREG_STATE] == STATE_CONNECTED ? 0 : (1<<5));
  183.  
  184.     dprintf(unit, 1, "sdcmd_query = %ld\n",iob->IOSer.io_Actual);
  185.  
  186.     ReleaseSemaphore(&unit->u_Modem->nm_Semaphore);
  187.  
  188.     return(iob);
  189. }
  190.  
  191. struct IOExtSer *
  192. sdcmd_break(struct IOExtSer *iob)
  193. {
  194. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  195.  
  196.     dprintf(unit, 1, "sdcmd_break (not implemented)\n");
  197.     return(iob);
  198. }
  199.  
  200. struct IOExtSer *
  201. sdcmd_setparams(struct IOExtSer *iob)
  202. {
  203. struct NullUnit *unit = (struct NullUnit *)iob->IOSer.io_Unit;
  204.  
  205.     dprintf(unit, 1, "sdcmd_setparams (does nothing)\n");
  206.     return(iob);
  207. }
  208.  
  209. #define ASDG_RTS (1<<0)
  210. #define ASDG_DTR (1<<1)
  211.  
  212. struct IOExtSer *
  213. asdg_dtrcontrol(struct IOExtSer *iob)
  214. {
  215. struct NullUnit *unit = iob->IOSer.io_Unit;
  216.  
  217.     dprintf(unit, 1, "asdg_dtrcontrol\n");
  218.  
  219.     if( ASDG_DTR & iob->IOSer.io_Offset )
  220.         if( ASDG_DTR & iob->IOSer.io_Length ) {
  221.             /* raise DTR */
  222.             dprintf(unit, 2,"asdg_dtrcontrol (raise DTR)\n");
  223.         }
  224.         else {
  225.             /* lower DTR */
  226.             dprintf(unit, 2,"asdg_dtrcontrol (lower DTR)\n");
  227.             Signal(unit->u_Modem->nm_Taskptr, SIGBREAKF_CTRL_D);
  228.         }
  229.  
  230.     if( ASDG_RTS & iob->IOSer.io_Offset )
  231.         if( ASDG_RTS & iob->IOSer.io_Length ) {
  232.             /* raise RTS */
  233.             dprintf(unit, 2,"asdg_dtrcontrol (raise RTS)\n");
  234.         }
  235.         else {
  236.             /* lower RTS */
  237.             dprintf(unit, 2,"asdg_dtrcontrol (lower RTS)\n");
  238.         }
  239.  
  240.     return(iob);
  241. }
  242.